<?php
/*
*后台订单展示
*/
/** * * ━━━━━━神兽出没━━━━━━
   * 　　　┏┓　　　┏┓
   * 　　┏┛┻━━━┛┻┓
   * 　　┃　　　　　　　┃
   * 　　┃　　　━　　　┃
   * 　　┃　┳┛　┗┳　┃
   * 　　┃　　　　　　　┃
   * 　　┃　　　┻　　　┃
   * 　　┃　　　　　　　┃
   * 　　┗━┓　　　┏━┛
   * 　　　　┃　　　┃       Code is far away from bug with the animal protecting
   * 　　　　┃　　　┃         神兽保佑,代码无bug
   * 　　　　┃　　　┗━━━┓
   * 　　　　┃　　　　　　　┣┓
   * 　　　　┃　　　　　　　┏┛
   * 　　　　┗┓┓┏━┳┓┏┛
   * 　　　　　┃┫┫　┃┫┫
   * 　　　　　┗┻┛　┗┻┛
   *  ━━━━━━感觉萌萌哒━━━━━━
   */
namespace app\admin\controller;
use think\Controller;
use think\Request;
use \think\Db;
class Order extends Base{

	 public function _initialize() {
        parent::_initialize (); 
      }

      /*
      * 订单列表
      */
     public function index(){
		$data = $this->data;
		$where = [];
		if(isset($data['order_no']) && !empty($data['order_no'])){
			$where['o.order_no'] = ["like","%{$data['order_no']}%"];
		}
		if(isset($data['phone']) && !empty($data['phone'])){
			$where['o.phone'] = ["like","%{$data['phone']}%"];
		}
		$field = "o.*,m.name as buy_name,u.name as cs_name"; 
		$list = Db::name(self::$tb['order'])->alias("o")
				->join("jun_member m","o.member_id = m.id","left")
				->join("jun_user u","u.id=o.uid","left")
				->where($where)->field($field)->paginate(10); 
		$datas = $list->all();   
		// foreach ($datas as $key => $value) {  
		// 	$value["manager_num"] = Db::name(self::$tb['user'])->alias("u")
		// 	->join("jun_role r","r.id = u.role_id","left")->where(["u.shop_id"=>$value['id'],"r.name"=>"业务经理"])->count("u.id"); 
		// 	$list[$key] = $value;
		// }    
		$page = $list->render();
		$this->assign("list",$list);
		$this->assign("page",$page); 
        return $this->fetch();
     }

   /*
   *订单详情
    */
    public function order_detail(){
   	    $data = $this->data;
		$check = $this->validate($data,'Order.order_detail');
		if($check !==true){
		  return api_return($check);
		}
   	    $where=['o.id',$data['id']];
   	    $field = "o.*,m.name as buy_name,u.name as cs_name"; 
		$detail = Db::name(self::$tb['order'])->alias("o")
				->join("jun_member m","o.member_id = m.id","left")
				->join("jun_user u","u.id=o.uid","left")
				->where($where)->field($field)->find(); 
		$this->assign("detail",$detail);	
        return $this->fetch();
    }
 
     /**
      * 添加/修改订单
      * @return [type] [description]
      */
     public function addorder(){
        return $this->fetch();
     }

}
